import esbuild from 'esbuild'
import fs from 'node:fs'
import { dirname, relative, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { createRequire } from 'node:module'

const require = createRequire(import.meta.url)
const __dirname = dirname(fileURLToPath(import.meta.url))

console.log("打包运行");

console.log(__dirname);

let packageName="reactivity";
let pkgBasePath="C://work//vscodeproject//bingo//packages//"+packageName;
let format="module";
const outfile = resolve(__dirname,`${pkgBasePath}/dist/${packageName}.js`,)

esbuild
.context({
    entryPoints: [resolve(__dirname, `${pkgBasePath}/src/index.ts`)],
    outfile,
    bundle: true,
    sourcemap: true,
    format: "esm",
    platform: format === 'cjs' ? 'node' : 'browser',
})
.then(ctx => ctx.watch())